﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ScrumTime.Models.Story>" %>


    <style>
	    /* style the list to maximize the droppable hitarea */
	    #div-acceptanceCriterias ol { margin: 0; padding: 1em 0 1em 3em; }
	</style>


    
	<script>
	    function editAcceptanceCriteria(idAcceptanceCriteria, idstory, idAffectedAcceptanceCriteria) {
	        var url = addURLRamdon('/Story/ShowStory_BasicData_AcceptanceCriteria_Edit');
            $.post(url,
                {
                    id: idAcceptanceCriteria,
                    idStory: idstory,
                    idAffectedAcceptanceCriteria: idAffectedAcceptanceCriteria
                },
                function (data) {                    
                    if (verificarError(data)) return;
                    $('#show-AcceptanceCriterias').html(data);
                }
            );
	    }

	    function new_AcceptanceCriteria(idstory) {
	        editAcceptanceCriteria(-1, idstory, -1)
	    }

	    function addaffectedAcceptanceCriteria(affectedAcceptanceCriteriaId, idstory) {
	        editAcceptanceCriteria(-1, idstory, affectedAcceptanceCriteriaId);
	    }


	    function showStory_deleteAcceptanceCriteria(acceptanceCriteriaId) {
	        
	        var storyid = $("#showStory_acceptanceCriterias_storyid").val();
	        jConfirm('This action removes the element. Are you sure you want to continue?', 'Confirmation Dialog', function (r) {
	            if (!r) return;
	            var url = addURLRamdon('/AcceptanceCriteria/Delete');
	            $.post(url,
                {
                    id: acceptanceCriteriaId,
                    acceptanceCriteriaId: acceptanceCriteriaId,
                    storyId: storyid
                },
                function (data) {
                    if (verificarError(data)) return;
                    refreshAcceptanceCriteriasList();
                });
	        });
	    }


	    function refreshAcceptanceCriteriasList() {
	        var storyid = $("#showStory_acceptanceCriterias_storyid").val();
	        var url = addURLRamdon('/Story/ShowStory_AcceptanceCriterias');
	        $.post(url,
                {
                    id: storyid
                },
                function (data) {
                    if (verificarError(data)) return;
                    $("#div_main_show_story_AcceptanceCriteriaList").html(data);
                }
            );
	    }

	    function editaffectedAcceptanceCriteria(affectedAcceptanceId, description) {
	        var old_description = $('#showStoryAcceptanceCriteria-description').val();
	        old_description = old_description + '\n' + '(added description)' + '\n';
	        old_description = old_description + description;
	        $('#showStoryAcceptanceCriteria-description').val(old_description);
	        $('#ol-acceptanceCriteria-uaffectedAC').append('<li  id="li_atac_' + affectedAcceptanceId + '" affectedAcceptanceCriteriaId="' + affectedAcceptanceId + '">' + description + ' <a href="#" onclick="remove_li_af_AcceptanceCriteria(' + affectedAcceptanceId + ')">&lt;remove&gt;</a></li>');
	    }

	    function remove_li_af_AcceptanceCriteria(affectedAcceptanceCriteriaId) {
	        $('#li_atac_' + affectedAcceptanceCriteriaId).remove();
	    }

	    $(function () {
	        $("#catalog_AffectedAcceptanceCriteria").accordion({
	            autoHeight: false,
	            navigation: true
	        });
	    });
	</script>

	
    <script type="text/C#" runat="server">
        private bool isAffectedAcceptanceCriteriaInStory(
                ScrumTime.Models.Story story,
                ScrumTime.Models.UsabilityAffectedAcceptanceCriteria affectedUsabilityCriteria
            ) {

                bool resultado = false;

                foreach (ScrumTime.Models.AcceptanceCriteria ac in story.AcceptanceCriterias)
                {
                    foreach (ScrumTime.Models.UsabilityAffectedAcceptanceCriteria uaffectedUC in  ac.UsabilityAffectedAcceptanceCriterias)
                    {
                        if (uaffectedUC.UsabilityAffectedAcceptanceCriteriaId == affectedUsabilityCriteria.UsabilityAffectedAcceptanceCriteriaId)
                        {
                            //resultado = true;
                            return true;
                        }
                    }
                }
            
                return resultado;            
        }
    </script>


    <input type="hidden" id="showStory_acceptanceCriterias_storyid" value="<%:Model.StoryId%>" />
    <table style="width:100%;">
        <tr>
            <td style="text-align:left; vertical-align:top; width:60%;">
                <div id="div-acceptanceCriterias">
                    
	                <h3 class="ui-widget-header" style="margin:0px; border:0px;">Acceptance Criteria</h3>
                    
	                <div id="show-AcceptanceCriterias" class="ui-widget" >                    
                    <div  class="ui-widget" style="border-width:1px;"> 
                        <a href="#" onclick="new_AcceptanceCriteria(<%:Model.StoryId%>);">New Acceptance Criteria</a> 
                    </div>
                        <table style="width:100%;">
                                <tr>
                                    <td style="width:20px; font-weight:bold;">id</td>                                    
                                    <td style="font-weight:bold;">Description</td>
                                    <td style="width:40px; font-weight:bold;">Acction</td>
                                </tr>
                        </table>
                        <table style="width:100%;">
                        <% foreach (ScrumTime.Models.AcceptanceCriteria acceptanceCriteria in Model.AcceptanceCriterias)
                           {
                          %>
                            <tr>
                            <% Html.RenderPartial("~/Views/Story/ShowStory_BasicData_AcceptanceCriteria_ReadOnly.ascx", acceptanceCriteria); %>    
                            </tr>
                        <% } 
                           %>
                        </table>
	                </div>
                </div>
            </td>
            <td style="text-align:left; vertical-align:top; width:60%;">            
                <div id="products">
                    <h3 class="ui-widget-header" style="margin:0px; border:0px;">Usability Acceptance Criteria</h3>
	                
	                <div id="catalog_AffectedAcceptanceCriteria">

                    <% foreach (ScrumTime.Models.Stories_UsabilityFeatures s_usabilityFeature in Model.Stories_UsabilityFeatures)
                       {%>

                            <h4><a href="#"> <%: s_usabilityFeature.UsabilityFeature.Name%></a></h4>
                            
                            <div style="padding:0px;">
                                <ul>
                                <% foreach (ScrumTime.Models.UsabilityAffectedAcceptanceCriteria affectedAcceptanceCriteria in s_usabilityFeature.UsabilityFeature.UsabilityAffectedAcceptanceCriterias)
                                   {                                        
                                       %>
                                    
                                        <li>
                                            <div>
                                                <% if (isAffectedAcceptanceCriteriaInStory(Model, affectedAcceptanceCriteria))
                                                   { %>
                                                   <a href="#" title="Implemented in a Acceptance Criteria" >                                                   
                                                    <span class="ui-icon ui-icon-circle-check" style="float:left" ></span>
                                                    </a>                                                
                                                <% } %>

                                                    <% if (affectedAcceptanceCriteria.Type.Contains("new"))
                                                       { %>
                                                    <a href="#" style="float:left" onclick="addaffectedAcceptanceCriteria(<%:affectedAcceptanceCriteria.UsabilityAffectedAcceptanceCriteriaId%>, <%:Model.StoryId%> );"title="add new Acceptance Criteria with this description">
                                                        <span class="ui-icon ui-icon-circle-plus"></span>
                                                    </a>
                                                    <% } %>
                                                
                                                    <% if (affectedAcceptanceCriteria.Type.Contains("edit"))
                                                       { %>
                                                    <a href="#"  style="float:left" onclick="editaffectedAcceptanceCriteria(<%:affectedAcceptanceCriteria.UsabilityAffectedAcceptanceCriteriaId%>, '<%:affectedAcceptanceCriteria.Description %>');" title="Modify the  Acceptance Criteria description">
                                                        <span class="ui-icon ui-icon-pencil"></span>
                                                    </a>
                                                    <% } %>
                                                <span>
                                                    <%:affectedAcceptanceCriteria.Description%>  
                                                    <% if (s_usabilityFeature.UsabilityFeature.HelpId != null)
                                                       { %>
                                                    <a title="Help"  href="#" onclick="mostrarAyuda( <%:affectedAcceptanceCriteria.UsabilityAffectedAcceptanceCriteriaId%> , <%:s_usabilityFeature.UsabilityFeature.HelpId%>, 'ac');" class="ui-icon ui-icon-help" ></a>
                                                    <% } %>
                                                </span>
                                            </div>
                                        </li>
                                <% }%>
			                    </ul>
		                    </div>

                    <%
                       }
                        %>
		                
		                
	                </div>
                </div>

            </td>
        </tr>
    </table>

